﻿using System;
using System.Windows.Forms;
using AppAcc.Models;

namespace AppAcc.Views.DanhMuc
{
    public partial class FormLoaiKhoThem : DevComponents.DotNetBar.RibbonForm
    {
        //private AppAccContext db = new AppAccContext();
        private PhanMenKeToanEntities1 db = new PhanMenKeToanEntities1();
        public FormLoaiKhoThem()
        {
            InitializeComponent();
        }

        private void txtTenLoaiKho_TextChanged(object sender, EventArgs e)
        {
            KiemTra();
        }

        private void bttLuu_Click(object sender, EventArgs e)
        {
            Create();
        }

        private void bttThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void Create()
        {
            try
            {
                var t = new LoaiKhoHang();
                t.DienGiai = txtDienGiai.Text;
                t.TenLoaiKhoHang = txtTenLoaiKho.Text;
                db.LoaiKhoHangs.Add(t);
                db.SaveChanges();
                Reset();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        void KiemTra()
        {
            if (txtTenLoaiKho.Text!="")
            {
                bttLuu.Enabled = true;
            }
            else
            {
                bttLuu.Enabled = false;
            }
        }

        void Reset()
        {
            txtDienGiai.Text = "";
            txtTenLoaiKho.Text = "";
            bttLuu.Enabled = false;
        }

        private void FormLoaiKhoThem_Load(object sender, EventArgs e)
        {
            Reset();
        }
    }
}
